package com.orange.shiro.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.orange.shiro.entiy.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UserMapper extends BaseMapper<User> {

    @Select("select name from role where id in (select rid from role_user where uid = (select id from user where name = #{principal}))")
    List<String> getUserRoleInfoMapper(@Param("principal") String principal);

    //前后分别添加了<script>、</script>，这是因为SQL中使用了动态sql标签<foreach>
    @Select({"<script>",
            "select info from permissions where id in " +
                    "(select pid from role_ps where rid in " +
                    "(select id from role where name in " +
                    "<foreach collection='roles' item='name' open='(' separator=',' close=')'> " +
                    "#{name} " +
                    "</foreach>" +
                    "))",
            "</script>"
    })
    List<String> getUserPermissionInfoMapper(@Param("roles") List<String> roles);
}
